#include "Timer.h"

Timer::Timer (void)
{
	IsActive = false;
	FPS_String = new char[MAX_CHAR];
}

Timer::~Timer (void)
{
	delete FPS_String;
}

void Timer::Start (void)
{
	IsActive = true;
	CurTickCount = GetTickCount();
	Update();
}

void Timer::Update (void)
{
	if (IsActive)
	{
		PrvTickCount = CurTickCount;
		CurTickCount = GetTickCount();
	}
}

void Timer::Stop (void)
{
	IsActive = false;
}

float Timer::GetFrameTime (void)
{
	FrameTime = (((float)CurTickCount - (float)PrvTickCount) / 1000.0f);
	return FrameTime;
}

float Timer::GetFPS (void)
{
	FPS = GetFrameTime();
	if (FPS > 0)
		FPS = (1.0f / FPS);
	else
		FPS = 0.0f;
	return FPS;
}

char* Timer::GetFPS_String (void)
{
	if (Converter.good())
	{
		Converter << GetFPS();
		strcpy_s(FPS_String, MAX_CHAR, Converter.str().c_str());
		Converter.str("");
	}
	else
		FPS_String = '\0';

	return FPS_String;
}